<!DOCTYPE html>
<html class="layui-bg-white">
<head th:include="include :: header"></head>
<body>
<div class="layui-form" style="padding:20px;">
    <input type="hidden" id="subjectName" name="subjectName">
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>科目：</label>
        <div class="layui-input-block">
            <select lay-filter="subjectId" id="subjectId" name="subjectId" class="form-control chosen-select" lay-search lay-verify="required">
                <option value="">--请选择--</option>
                <option th:each="item : ${subject}" th:value="${item.id}" th:text="${item.name}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>类型：</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="问答" checked>
            <input type="radio" name="type" value="2" title="论文">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>题号：</label>
        <div class="layui-input-block">
            <input type="text" id="sortNumber" name="sortNumber" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="required">*</span>题目：</label>
        <div class="layui-input-block">
            <textarea id="name" name="name" lay-verify="required" class="layui-textarea" placeholder="请输入题目"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">答案：</label>
        <div class="layui-input-block">
            <textarea id="answer" name="answer" class="layui-textarea" placeholder="请输入答案"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">答案解析：</label>
        <div class="layui-input-block">
            <textarea id="answerAnalysis" name="answerAnalysis" class="layui-textarea" placeholder="请输入答案解析"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-operate-submit" id="LAY-operate-submit" value="确认">
    </div>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">
    var synthesisQuestion = {};
    layui.config({
        base: ctx + '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index'         //主入口模块
    }).use(['index', 'form', 'layedit'], function () {
        var $ = layui.$, form = layui.form, layedit = layui.layedit;

        form.verify(commonJs.form.verify);

        form.on('select(subjectId)', function (data) {
            var value = data.value || '';
            var text = '';
            if (value != '') {
                text = data.elem[data.elem.selectedIndex].text || '';
            }
            $('#subjectName').val(text);
        });

        //初始和获取富文本的内容
        layedit.set({
            uploadImage: {
                url: ctx + '/manage/file/file/layedit' //接口url
            }
        });
        var nameIndex = layedit.build('name');
        var answerIndex = layedit.build('answer');
        var answerAnalysisIndex = layedit.build('answerAnalysis');

        //初始化form的数据
        synthesisQuestion.initFormData = function () {
            $('#name').val(layedit.getContent(nameIndex));
            $('#answer').val(layedit.getContent(answerIndex));
            $('#answerAnalysis').val(layedit.getContent(answerAnalysisIndex));
        }
    })
</script>
</body>
</html>